using SmartCommunity.Models;
using Mapster;
using System.ComponentModel.DataAnnotations;

namespace SmartCommunity.WebApi.Services.System
{
    #region DTO属性映射
    /// <summary>
    /// 属性映射 ConfigDtoRegister
    /// </summary>
    public class ConfigDtoRegister : IRegister
    {
        public void Register(TypeAdapterConfig config)
        {
            // config.ForType<ConfigEntity, ConfigDto>().Map(d => d.DeptName, s => s.Dept.DeptName, s => s.Dept != null);
        }
    }
    #endregion

    #region 数据传输对象 ConfigDto
    /// <summary>
    /// 数据传输对象：参数配置
    /// </summary>
    public class ConfigDto : BaseDto
    {
        /// <summary>
        /// 参数ID
        /// </summary>
        public int ConfigId { get; set; }

        /// <summary>
        /// 参数名称
        /// </summary>
        [Required(ErrorMessage = "参数名称不能为空")]
        [StringLength(50, ErrorMessage = "参数名称 长度不能超过 50.")]
        public string ConfigName { get; set; } = string.Empty;

        /// <summary>
        /// 参数编码
        /// </summary>
        [Required(ErrorMessage = "参数编码不能为空")]
        [StringLength(100, ErrorMessage = "参数编码 长度不能超过 100.")]
        public string ConfigKey { get; set; } = string.Empty;

        /// <summary>
        /// 参数值
        /// </summary>
        [Required(ErrorMessage = "参数值不能为空")]
        [StringLength(500, ErrorMessage = "参数值 长度不能超过 500.")]
        public string ConfigValue { get; set; } = string.Empty;

        /// <summary>
        /// 扩展字段
        /// </summary>
        [StringLength(200, ErrorMessage = "扩展字段 长度不能超过 200.")]
        public string? ExtField { get; set; }

        /// <summary>
        /// 备注说明
        /// </summary>
        [StringLength(255, ErrorMessage = "备注说明 长度不能超过 255.")]
        public string? Remark { get; set; }

    }
    #endregion

    #region 数据查询对象
    /// <summary>
    /// 查询模型：参数配置
    /// </summary>
    public class ConfigQuery : AbstractQuery<ConfigEntity>
    {
        /// <summary>
        /// 主键ID多选查询
        /// </summary>
        public IEnumerable<int> Ids { get; set; } = [];

        /// <summary>
        /// 根据查询条件添加查询表达式
        /// </summary>
        protected override void MergeQueryExpression()
        {
            AddExpression(Ids.Any(), e => Ids.Contains(e.ConfigId));
            AddSearchExpression(s => o => o.ConfigKey.Contains(s) || o.ConfigName.Contains(s));
            AddDateExpression(start => e => e.CreatedTime >= start, end => e => e.CreatedTime <= end);
        }
    }
    #endregion
}
